﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
using Eb;

namespace Ec
{
    public class EcEngineListener : IEcEngineListener
    {
        //---------------------------------------------------------------------
        public void init(EntityMgr entity_mgr, Entity et_node)
        {
            entity_mgr.regComponent<ClientApp<DefApp>>();

            entity_mgr.regEntityDef<EtApp>();

            entity_mgr.createEntity<EtApp>(null, et_node);
        }

        //---------------------------------------------------------------------
        public void release()
        {
        }
    }

    class Program
    {
        //---------------------------------------------------------------------
        static EcEngine mEngine;
        static Stopwatch mStopwatch = new Stopwatch();
        const float mTimeLogicGap = 50.0f;// 毫秒
        static ILogFactory mLogFactory = null;

        //---------------------------------------------------------------------
        static void Main(string[] args)
        {
            Console.Title = "EcBots4StressTest";
            Console.ForegroundColor = ConsoleColor.Green;
            EbLog.NoteCallback = Console.WriteLine;
            EbLog.WarningCallback = Console.WriteLine;
            EbLog.ErrorCallback = Console.WriteLine;

            EcEngineSettings settings;
            settings.ProjectName = "EcBots4StressTest";
            settings.RootEntityType = "EtRoot";
            settings.EnableComponentUCenter = true;
            mEngine = new EcEngine(ref settings, new EcEngineListener());

            // 每帧更新
            while (true)
            {
                try
                {
                    mEngine.update(0.1f);

                    Thread.Sleep(100);
                    if (Console.KeyAvailable) break;
                }
                catch (Exception ec)
                {
                    EbLog.Error("EsTestSuperSocket.Main() Exception: " + ec);
                }
            }

            EbLog.Note("开始销毁...");
            Console.ReadKey(true);

            // 销毁
            if (mEngine != null)
            {
                mEngine.close();
                mEngine = null;
            }

            EbLog.Note("按任意键退出...");
            Console.ReadKey(true);
        }
    }
}
